﻿using System;
using System.Collections.Generic;
using System.Xml.Serialization;
using tjb.Utility.Config;
namespace tjb.Utility.Gather
{
    /// <summary>
    /// 采集配置
    /// </summary>
    [Serializable()]
    [XmlRoot("GatherConfig")]
    public class GatherConfiguration : ConfigBase<GatherConfiguration>
    {
        #region Public Properties
        /// <summary>
        /// 
        /// </summary>
        public List<Rule> GatherRules
        {
            set;
            get;
        }
        /// <summary>
        /// 
        /// </summary>
        public List<InitRule> Init
        {
            get;
            set;
        }
        /// <summary>
        /// 
        /// </summary>
        public List<ArticleRule> Article;

        /// <summary>
        /// 图片路径
        /// </summary>
        public string FilesPath
        {
            get;
            set;
        }
        /// <summary>
        /// HTML模板
        /// </summary>
        public string HtmlTemplate
        {
            get;
            set;
        }
        private SaveType _SaveType = SaveType.HTML;
        /// <summary>
        /// 数据存储方式
        /// </summary>

        public SaveType SaveType
        {
            get
            {
                return _SaveType;
            }
            set
            {
                _SaveType = value;
            }
        }
        /// <summary>
        /// 插入语句
        /// </summary>
        public string InsertSql { get; set; }
        /// <summary>
        /// 检测是否存在
        /// </summary>
        public string ChkSql { get; set; }
        /// <summary>
        /// 最大线程数
        /// </summary>
        public int MaxThreadCount = 10;
        /// <summary>
        /// 最大队列数
        /// </summary>
        public int MaxQueue = 50;
        /// <summary>
        /// 采集周期
        /// </summary>
        public int GatherPeriod = 5000;
        #endregion
        /// <summary>
        /// 
        /// </summary>
        protected override GatherConfiguration Current
        {

            get
            {
                return this;
            }
        }
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        protected override GatherConfiguration CustomizingInit()
        {
            Init = new List<InitRule>();
            InitRule irule = new InitRule();
            irule.Coding = "xx";
            irule.GatherRules = new List<Rule>();
            Rule r = new Rule();
            r.End = "swweeee\twesadf\r\neeewew";
            r.NewStr = "ww";
            r.RegexPattern = "<?name>dsa";
            r.Primality = "<?name>adsfaweweqerqdsa";
            int i = 3;
            while (i-- > 0)
                irule.GatherRules.AddRange(new Rule[] { r, r, r, r, r, r });

            Init.Add(irule);

            return this;
        }

    }


}
